package com.tanhua.sso.controller;

import com.tanhua.sso.service.HuanXinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: Administrator
 * @date: Created in 2021/2/23 21:01
 * @version: 0.0.1
 * @modified By:
 */
@RestController
@RequestMapping("user/huanxin")
public class HuanXinController {

    @Autowired
    private HuanXinService huanXinService;

    @PostMapping("contacts/{owner_username}/{friend_username}")
    public ResponseEntity<Void>contactUsers(@PathVariable("owner_username")Long userId,
                                            @PathVariable("friend_username")Long friendId){
        try {
            Boolean bool = this.huanXinService.contactUsers(userId, friendId);
            if(bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build() ;
    }
    /**
     * @description 发送系统消息
     * @author
     * @date
     * @paramL
     *@return
     */
    @PostMapping("messages")
    public ResponseEntity<Void>sendMsg(@RequestParam("target")String target,
                                       @RequestParam("msg")String msg,
                                       @RequestParam(value = "type",defaultValue = "txt")String type){
        try {
            Boolean bool= this.huanXinService.sendMsg(target,msg,type);
            if(bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build() ;
    }
}
